package controller;

import com.github.pagehelper.PageInfo;
import domain.Orders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import service.OrdersService;


@Controller
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @RequestMapping("/all")
    public ModelAndView all(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "5") int pageSize){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("order_all");
        PageInfo<Orders> ordersAll = ordersService.findOrdersAll(pageNum, pageSize);
        modelAndView.getModel().put("ordersAll",ordersAll);
        return modelAndView;
    }

    @RequestMapping("/desc")
    public ModelAndView desc(String id){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("order_desc");
        Orders orders = ordersService.findOrdersById(id);
        modelAndView.getModel().put("orders",orders);
        return modelAndView;
    }
}
